package com.yunyike.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yunyike.mapper.BrandMapper;
import com.yunyike.model.Brand;
import com.yunyike.service.BrandService;

@Service("brandServiceImpl")
public class BrandServiceImpl implements BrandService{

	private Logger log = LoggerFactory.getLogger(BrandServiceImpl.class);

	@Autowired
	private BrandMapper brandMapper;
	
	public Brand selectBrandByQuotationId(String quotationId) {
		List<Brand> brans = brandMapper.selectBrandByQuotationId(quotationId);
		return  brans==null?null:brans.get(0);
	}
	
	/**
	 * 获取所有品牌
	 */
	public List<Brand> findAllBrand() {
		return brandMapper.findAllBrand();
	}

	/**
	 * 根据品牌id查询品牌（多个）
	 */
	public Map<String, Brand> findBrandsByIds(List<String> brandIds) {
		
		List<Brand> findBrandsByIds = brandMapper.findBrandsByIds(brandIds);
		if(findBrandsByIds == null || findBrandsByIds.isEmpty()){
			return null;
		}
		
		Map<String, Brand> brandMap = new HashMap<String, Brand>();
		for (Brand brand : findBrandsByIds) {
			String brandIdDB = brand.getBrandId();
			for (String brandId : brandIds) {
				if(brandIdDB.equals(brandId)){
					brandMap.put(brandId, brand);
					break;
				}
			}
		}
		
		return brandMap;
	}

	public Brand findBrandById(String brandId) {
		return brandMapper.selectByPrimaryKey(brandId);
	}
	
}
